package project.db.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Database {
	public Database() {
		initialized = initDatabaseConnection();
	}

	private boolean initDatabaseConnection() {
		connection = null;
		try {
			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
			connection = DriverManager.getConnection(DATABASE, USER, PASSWORD);
			return true;
		} catch (SQLException error) {
			return false;
		}
	}

	public List<String> performSimpleSelectQuery(String table, String columns, String where) {
		List<String> result = new ArrayList<String>();

		if (initialized) {
			try {
				PreparedStatement statement = connection.prepareStatement("SELECT " + columns + "FROM " + table
						+ (where.equals(EMPTY) ? EMPTY : " WHERE " + where));
				statement.execute();
				ResultSet resultSet = statement.getResultSet();

				if (resultSet != null) {
					while (resultSet.next()) {
						// DO SOMETHING
					}
				}
			} catch (Exception error) {
				error.printStackTrace();
			}
		}

		return result;
	}

	private final String	DATABASE	= "DATABASEURL";
	private final String	USER		= "DATABASEUSER";
	private final String	PASSWORD	= "DATABASEPASSWORD";
	private final String	EMPTY		= "";

	private Connection		connection;
	private boolean			initialized	= false;
}
